module Shape {
	export class ArcTest extends egret.DisplayObjectContainer {
		private _shape: egret.Shape;

		/**
		 * 构造函数
		 */
		public constructor() {
			super();
			this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
		}

		/**
		 * 添加到舞台监听器
		 */
		private onAddToStage(event: egret.Event) {
			this._shape = new egret.Shape();
			this._shape.x=this.stage.stageWidth/2;
			this._shape.y=this.stage.stageHeight/2;
			this.addChild(this._shape);
			this.drawArc();
			this.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,()=>{
				this.drawArc();
			},this);
		}

		private _count:number=0;
		/**
		 * 画曲线 
		 */
		private drawArc():void{
			var nums:Array<number>=[18,15,12,10,9,6,5,4,3];
			var num:number=nums[this._count];
			this._count=(this._count+1)%nums.length;
			var singleAng: number = 180 / num;

			var r1 = 150;
			var r2 = r1 * Math.sin(singleAng * Math.PI / 180);
			var r3 = r1 * Math.cos(singleAng * Math.PI / 180);

			this._shape.graphics.clear();
			this._shape.graphics.lineStyle(2, 0xff0000 + Math.floor(Math.random() * 100) * (0xffffff / 100));
			this._shape.graphics.drawCircle(0,0,r1);
			this._shape.graphics.moveTo(-r1,0);
			this._shape.graphics.lineTo(r1,0);
			this._shape.graphics.moveTo(0,-r1);
			this._shape.graphics.lineTo(0,r1);

			for (var i: number = 0; i < num; i++) {
				this._shape.graphics.lineStyle(2, 0xff0000 + Math.floor(Math.random() * 100) * (0xffffff / 100));
				var ang =-singleAng + i * 2 * singleAng;
				this._shape.graphics.drawArc(r3*Math.cos(ang*Math.PI/180),r3*Math.sin(ang*Math.PI/180),r2,
				(ang+90)*Math.PI/180,(ang-90)*Math.PI/180,true);
			}
		}
	}
}